﻿package mortal.game.scene3D.display3d.text3d.staticText3d
{
    import __AS3__.vec.*;
    import mortal.game.scene3D.display3d.text3d.*;

    public class VcList extends Object
    {
        private var maxNum:uint;
        public var list:Vector.<Number>;
        public var placePool:Vector.<Stext3DPlace>;
        private var hasUseNum:int = 0;
        public static var totalUseNum:int = 0;

        public function VcList()
        {
            this.maxNum = SText3DRender.instance.maxNum;
            this.list = new Vector.<Number>;
            this.placePool = new Vector.<Stext3DPlace>;
            this.placePool.length = this.maxNum;
            this.list.length = this.maxNum * 4;
            return;
        }// end function

        public function getPlaces(param1:int, param2:Vector.<Stext3DPlace>) : Boolean
        {
            var _loc_5:Stext3DPlace = null;
            if (this.hasUseNum + param1 > this.maxNum)
            {
                return false;
            }
            this.hasUseNum = this.hasUseNum + param1;
            totalUseNum = totalUseNum + param1;
            var _loc_3:int = 0;
            var _loc_4:int = 0;
            while (_loc_4 < this.maxNum)
            {
                
                _loc_5 = this.placePool[_loc_4];
                if (!_loc_5)
                {
                    _loc_5 = new Stext3DPlace(this, _loc_4);
                    this.placePool[_loc_4] = _loc_5;
                    var _loc_6:* = _loc_3 + 1;
                    param2[_loc_6] = _loc_5;
                    _loc_5.isUsed = true;
                }
                else if (!_loc_5.isUsed)
                {
                    var _loc_6:* = _loc_3 + 1;
                    param2[_loc_6] = _loc_5;
                    _loc_5.isUsed = true;
                }
                if (_loc_3 == param1)
                {
                    return true;
                }
                _loc_4++;
            }
            throw new Error("vclist：取得NUM个位置出错");
        }// end function

        public function clearSplace(param1:Stext3DPlace) : void
        {
            if (this.placePool[param1.placeId] == param1)
            {
                if (param1.isUsed)
                {
                    param1.isUsed = false;
                    var _loc_2:String = this;
                    var _loc_3:* = this.hasUseNum - 1;
                    _loc_2.hasUseNum = _loc_3;
                    var _loc_3:* = totalUseNum - 1;
                    totalUseNum = _loc_3;
                }
            }
            else
            {
                throw new Error("删除splace出错了");
            }
            return;
        }// end function

        public function dispose() : void
        {
            var _loc_2:Stext3DPlace = null;
            var _loc_1:int = 0;
            while (_loc_1 < this.maxNum)
            {
                
                _loc_2 = this.placePool[_loc_1];
                if (_loc_2)
                {
                    _loc_2.isUsed = false;
                    this.list[_loc_2.placeId * 4 + 3] = -1000;
                }
                _loc_1++;
            }
            this.hasUseNum = 0;
            return;
        }// end function

    }
}
